<template>
  <el-card-comon>
    <template>
      <!-- 搜索按钮 -->
      <el-btn-serch-input
        :queryInfo="page"
        inputContentClearEmitName="searchClear"
        searchEmitName="searchBtnClick"
        :isShowRightBtn="false"
      />

      <!-- table -->
      <LogTable :logData="logs" />

      <!-- 分页组件 -->
      <el-pagination-com
        :nowPage.sync="page.pageNum"
        :pageNumber.sync="page.pageSize"
        :total="total"
        changeSizeName="changePageNumber"
        changeSizeNumberName="changeNowSize"
      />
    </template>
  </el-card-comon>
</template>

<script>
// 组件
import ElCardComon from '@/components/common/ElCardComon';
import ElPaginationCom from '@/components/common/ElPaginationCom';
import ElBtnSerchInput from '@/components/common/ElBtnSerchInput';
import LogTable from '@/views/Main/report/reportComponents/LogTable';

// 请求
import { findLogsByPage } from '@/network/reportRequest.js';

export default {
  data() {
    return {
      logs: [],
      page: {
        query: '',
        pageNum: 1,
        pageSize: 5
      },
      total: 0
    }
  },
  methods: {
    /**
     * 分页查询
     */
    async getLogList() {
      // console.log(this.page);
      const {meta, data} = await findLogsByPage(this.page);

      if (meta.status != 200) { return this.$message.error(meta.msg); }

      this.logs = data.page.list;
      this.total = data.page.total;
      // console.log(data);
    }

  },
  created() {
    this.$bus.$on('searchClear', () => {
      this.page.pageNum = 1;
      this.getLogList();
    });
    this.$bus.$on('searchBtnClick', this.getLogList);
    this.$bus.$on('changePageNumber', this.getLogList);
    this.$bus.$on('changeNowSize', this.getLogList);
    this.getLogList();
  },
  destroyed() {
    this.$bus.$off('searchClear');
    this.$bus.$off('searchBtnClick');
    this.$bus.$off('changePageNumber');
    this.$bus.$off('changeNowSize');
  },
  components: {
    ElCardComon,
    ElPaginationCom,
    ElBtnSerchInput,
    LogTable
  }
}
</script>
